package net.jueb.springStudy.ribbon.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class TestService {
	
    @Autowired 
    RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "serviceFailure")
    public String test() {
    	//restTemplate.getForObject方法会通过ribbon负载均衡机制， 自动选择一个logicA服务
    	//这里的URL是“http://logicA/"，其中的logicA是test服务的名字
        return restTemplate.getForObject("http://logicA/test",String.class);
    }
    
    public String serviceFailure() {
        return "service is not available !(ribbon)";
    }
}